package tabbedCanvas;

import java.awt.Dimension;

import javax.swing.JPanel;

/**
 * JPanel where xCenter and yCenter gives the center of the canvas. xCenter and yCenter is used to
 * offset other draw commands so that it will recognize 0,0 as the center of the JPanel, not
 * the top left corner
 * 
 * @author KevinWang
 *
 */
public class CenteredLayer extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected int xCenter;
	protected int yCenter;
	protected Dimension dimension;
	
	public CenteredLayer(Dimension dimension){
		super();
		this.dimension = dimension;
		initializePanel(dimension);
		setCenter(dimension);
	}
	
	/**
	 * set xCenter and yCenter
	 * @param dimension
	 */
	protected void setCenter(Dimension dimension) {
		xCenter = (int) (dimension.getWidth()/2);
		yCenter = (int) (dimension.getHeight()/2);
	}
	
	/**
	 * Initialize Panel
	 * @param dimension - dimension of the panel
	 */
	protected void initializePanel(Dimension dimension) {
		setPreferredSize(dimension);
		setVisible(true);
		setOpaque(false);
		setBounds(0,0, (int)dimension.getWidth(), (int)dimension.getHeight());
	}
}
